package com.ucomm.talent.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import com.ucomm.talent.R;
import com.ucomm.talent.adapter.CustomListAdapter;
import com.ucomm.talent.widget.MainHeaderBar;
import me.maxwin.view.IXListViewLoadMore;
import me.maxwin.view.IXListViewRefreshListener;
import me.maxwin.view.XListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 招聘信息列表界面
 * Created with IntelliJ IDEA.
 * User: Vita Hao
 * Date: 13-5-22
 * Time: 下午5:41
 * To change this template use File | Settings | File Templates.
 */
public class JobsActivity extends BaseActivity implements IHeaderBarClickListener{
    private XListView listView;
    private List<Map<String, Object>> mData;
    private MainHeaderBar mainHeaderBar;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jobs_layout);
        initView();
    }

    private void initView(){
        mainHeaderBar = (MainHeaderBar) findViewById(R.id.main_header_bar);
        mainHeaderBar.setBarClickListener(this);

        listView = (XListView) findViewById(R.id.custom_list);
        listView.setmHeaderViewBackground(R.color.custom_list_item_bg_color);
        listView.setmFooterViewBackground(R.color.custom_list_item_bg_color);
        listView.setPullLoadEnable(new IXListViewLoadMore() {
            @Override
            public void onLoadMore() {

            }
        });

        listView.setPullRefreshEnable(new IXListViewRefreshListener() {
            @Override
            public void onRefresh() {
            }
        });

        mData = getData();
        CustomListAdapter adapter = new CustomListAdapter(this,mData);
        listView.setAdapter(adapter);

    }

    private List<Map<String, Object>> getData() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "G1");
        map.put("info", "google 1");


        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G2");
        map.put("info", "google 2");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.btnico01);
        list.add(map);
        return list;
    }

    /**
     * listview中点击按键弹出对话框
     */
    public void showInfo(){
        new AlertDialog.Builder(this)
                .setTitle("我的listview")
                .setMessage("介绍...")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                })
                .show();

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();    //To change body of overridden methods use File | Settings | File Templates.
        finish();
    }

    /**
     * 监听返回
     */
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        boolean flag = true;
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Log.i("vita","-----onKeyDown");
            overridePendingTransition(R.anim.slide_left_out, R.anim.slide_left_in);
            finish();
        }
        return flag;
    }

    @Override
    protected void onDestroy() {

        super.onDestroy();    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public void onBackButtOnClick(View view) {
        finish();
    }

    @Override
    public void onExitButtonOnClick(View view) {

    }
}